package com.st.kafkademon;

/**
 * @author wuxianwei on 15/11/19.
 */
public class KafkaConsumerProducerDemo {
  public static void main(String[] args) {
    KafkaProducer producer = new KafkaProducer(KafkaProperties.kafkaServerURL, KafkaProperties.kafkaServerPort);
    producer.sendMessage("message1", KafkaProperties.topic1);
    producer.sendMessage("message2", KafkaProperties.topic1);
    producer.sendMessage("message3", KafkaProperties.topic1);

    KafkaConsumer consumerThread = new KafkaConsumer(KafkaProperties.topic1);
    consumerThread.start();

    try {
      Thread.sleep(5000l);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    //因为consumer是阻塞的 下边两条消息也难收到
    producer.sendMessage("message4", KafkaProperties.topic1);
    producer.sendMessage("message5", KafkaProperties.topic1);
    producer.sendMessage("message6", KafkaProperties.topic1);
  }

}
